﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASoft.Led
{
    public class LedPicWeather : LedPicBase
    {
        public LedPicWeather(LedCfg ledCfg, string ledPath) : base(ledCfg, ledPath) { }

        protected override string GetTemplatePicName()
        {
            return "weather.bmp";
        }

        protected override string GetSendPicName()
        {
            return "weather1.bmp";
        }

        public override void Create(params object[] ps)
        {
            PrivateCreate(ps[0] as WeatherData);
        }

        public void PrivateCreate(WeatherData wData)
        {
            List<DrawItem> drawItems = new List<DrawItem>();

            ProcessR(typeof(WeatherData), wData, typeof(WeatherItem), LedCfg.Weather, 1, 5, drawItems);

            CreatePic(drawItems);
        }

        void ProcessR(Type dataType, object rData, Type itemType, object rItem, int startIndex, int endIndex, List<DrawItem> drawItems)
        {
            var tRItem = typeof(RItem);
            for (int i = startIndex; i <= endIndex; i++)
            {
                int x = (int)itemType.GetProperty(String.Format("Cell{0}X", i)).GetValue(rItem, null);
                int y = (int)itemType.GetProperty(String.Format("Cell{0}Y", i)).GetValue(rItem, null);
                string text = (string)dataType.GetProperty(String.Format("Text{0}", i)).GetValue(rData, null);
                drawItems.Add(new DrawItem(text, x, y));
            }
        }
    }
}
